#include "Unit_Stop.h"

#include "../Game.h"
#include "../GameControl.h"
#include "../../tools/Log.h"

#include <cstring>

string Unit_Stop::command = "stop unit";

string Unit_Stop::toString() { return string(serialize().data); }

SerializedGameCommand Unit_Stop::serialize() const
{
	SerializedGameCommand cmd;
	sprintf(cmd.data, "%s %lu", command.c_str(), timestamp);
	return cmd;
}

Unit_Stop* Unit_Stop::interpret(const SerializedGameCommand& sgc)
{
	if (strncmp(sgc.data, command.c_str(), command.size()) == 0)
	{
		Unit_Stop* cmd = new Unit_Stop();
		if(sscanf(sgc.data, "stop unit %lu", &(cmd->timestamp)) == 1)
			return cmd;
	}
	
	return NULL;
}

Unit_Stop* Unit_Stop::interpret(const char* line)
{
	if (strncmp(line, command.c_str(), command.size()) == 0)
	{
		Unit_Stop* cmd = new Unit_Stop();
		if(sscanf(line, "stop unit %lu", &(cmd->timestamp)) == 1)
			return cmd;
		else if(sscanf(line, "stop unit") == 0)
			return cmd;
		
		lout << Unit_Stop::command << " error: Invalid arguments" << endl;
		delete cmd;
	}
	
	return NULL;
}

void Unit_Stop::onExecute()
{
	// -- BEGIN CUSTOM CODE REGION -- //// -- END CUSTOM CODE REGION -- //
}
